package com.example.administrator.kaohedemo.Activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import com.example.administrator.kaohedemo.Action.Actions;
import com.example.administrator.kaohedemo.Action.TaskAction;
import com.example.administrator.kaohedemo.Adapter.TaskAdapter;
import com.example.administrator.kaohedemo.R;
import com.example.administrator.kaohedemo.Store.Store;
import com.example.administrator.kaohedemo.Store.TaskStore;
import com.squareup.otto.Subscribe;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity {
    protected TaskAction actionCreator;
    private RecyclerView task_list;
    List<String> list=new ArrayList<String>();

    @Override
    protected void initView() {
        setContentView(R.layout.activity_main);
        actionCreator= (TaskAction) TaskAction.getInstense();
        task_list= (RecyclerView) findViewById(R.id.task_list);
        task_list.setHasFixedSize(true);
        task_list.setLayoutManager(new LinearLayoutManager(this));
        setData();
        TaskAdapter adapter=new TaskAdapter(this,list);
        task_list.setAdapter(adapter);
    }

    private void setData() {
        list.add("课程");
        list.add("活动");
        list.add("作业");
        list.add("日志");
        list.add("资源");
        list.add("问答");
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected Store getStore() {
        return TaskStore.getInstense();
    }

    @Override
    public void onClick(View view) {

    }

    @Subscribe
    public void TaskStoreChanged(TaskStore.TaskStoreChanged tt){
        switch (tt.getType()){
            case Actions.TaskActions.TYPE_ITEM_ONCLICK:
                if (tt.getPosition()==0) {
                    startActivity(new Intent(this,CourseListActivity.class));
                }else {
                    Toast.makeText(this, getResources().getString(R.string.task_not_open), Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }
}
